#include "editarchdialog.h"
#include "componentstab.h"
#include "triggerstab.h"
#include "attributestab.h"


EditArchDialog::EditArchDialog(AED_Archtype &arch,ImageManager *manager,ImageModel *img_model,ScriptModel *smodel, QWidget *parent) :
    QDialog(parent),m_arch(arch)
{
    QVBoxLayout *main_layout = new QVBoxLayout;
    this->setLayout(main_layout);

    QHBoxLayout *name_layout = new QHBoxLayout;

    QLabel *label = new QLabel(tr("Name:"));
    name_layout->addWidget(label);
    QLineEdit *line = new QLineEdit(arch.GetName());
    name_layout->addWidget(line);

    main_layout->addLayout(name_layout);

    QTabWidget *tab_widget = new QTabWidget();

    tab_widget->addTab(new ComponentsTab(&m_arch,manager,img_model),"Components");
    TriggersTab *ttab = new TriggersTab(&m_arch,smodel);
    tab_widget->addTab(ttab,"Triggers");
    tab_widget->addTab(new AttributesTab(&m_arch),"Attributes");
    main_layout->addWidget(tab_widget);


    QHBoxLayout *button_layout = new QHBoxLayout;

    QPushButton *okButton = new QPushButton("OK");
    QPushButton *cancelButton = new QPushButton("Cancel");
    button_layout->addWidget(okButton);
    button_layout->addWidget(cancelButton);
    button_layout->setAlignment(Qt::AlignRight);
    main_layout->addLayout(button_layout);



    connect(line, SIGNAL(textEdited(QString)),
             this, SLOT(UpdateName(const QString&)));
    connect(okButton, SIGNAL(clicked()),
             this, SLOT(accept()));
    connect(cancelButton, SIGNAL(clicked()),
             this, SLOT(reject()));

    connect(tab_widget,SIGNAL(currentChanged(int)),ttab,SLOT(UpdateTypes(int)));



}

AED_Archtype EditArchDialog::GetArchtype(){
    return m_arch;
}

void EditArchDialog::UpdateName(const QString &name){
    m_arch.SetName(name);
}


